package com.turing.post.webservice.impl;

import java.text.ParseException;
import java.util.Hashtable;
import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.turing.post.datatranferpmbs.util.PMBSMchTradDetailBusiness;
import com.turing.post.util.PCPSApplicationException;

/**
 * @author zxp
 * @Jan 27, 2013
 */
public class TranferDataTest {

	/**
	 * @param args
	 * @throws ParseException
	 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws ParseException {
		// 用户登录成功信息检测
		Context ctx = null;
		// 根据客户端传来的名字查找相应的实现EJB
		PMBSMchTradDetailBusiness dao = null;
		String name = "datatranferpmbs.impl.PMBSMchTradDetailBusinessImpl"
				+ "#" + PMBSMchTradDetailBusiness.class.getName();

		Hashtable env = new Hashtable();
		env.put(InitialContext.INITIAL_CONTEXT_FACTORY,
				"weblogic.jndi.WLInitialContextFactory");
		env.put(InitialContext.PROVIDER_URL, "t3://127.0.0.1:7001");

		try {
			ctx = new InitialContext(env);
		} catch (NamingException e1) {
			e1.printStackTrace();
		}

		try {
			dao = (PMBSMchTradDetailBusiness) ctx.lookup(name);
		} catch (NamingException e) {
			e.printStackTrace();
		}
		// String merchantNo = "0023";
		List<Object[]> objList = dao.getMchTradDetailTranDateList();
		Object[] objs = null;
		long all = System.currentTimeMillis();
		for (int i = 0; i < objList.size(); i++) {
			objs = objList.get(i);
			System.out.println("Start 条数：" + objs[1]);
			long l = System.currentTimeMillis();
			objs = objList.get(i);
			try {
				dao.transferPMBSMchTradDetail("", objs[0].toString());
			} catch (PCPSApplicationException e) {
				e.printStackTrace();
			}
			System.out.println("End 耗时：" + (System.currentTimeMillis() - l)
					/ 1000);
		}
		System.out.println("总耗时：" + (System.currentTimeMillis() - all) / 1000);

		// 只根据日期迁移
		// long all = System.currentTimeMillis();
		// try {
		// dao.transferPMBSMchTradDetail("", "2010-12-31");
		// } catch (PCPSApplicationException e) {
		// e.printStackTrace();
		// }
		// System.out.println("总耗时：" + (System.currentTimeMillis() - all) /
		// 1000);

		// BigInteger seqno = new BigInteger("1");
		// seqno = seqno.mod(new BigInteger("1000000"));
		// System.out.print(String.format("%06d", seqno));

		// List<CardTradDetail> ctdList = dao.getCardTradDetailList(8531, 0);
		// System.out.println(ctdList.size() + "=");
	}

}
